package com.common.myspring.aspect;

import com.common.myspring.annotation.Component;
import com.common.myspring.annotation.LogAnnotation;
import com.common.myspring.annotation.aop.Aspect;
import com.common.myspring.annotation.aop.PointCut;

import java.lang.reflect.Method;

/**
 * @title: MyAspect
 * @Author xu-xiang
 * @Date: 2023/8/31 18:05
 * @description:
 */
@Component
@Aspect
public class MyAspect {

    @PointCut(pointCut = LogAnnotation.class)
    public Object around(Object o, Method method, Object[] objects) throws Exception {

        Object proceed = null;
        try {
            System.out.println("代理方法" + method.getName() + "before开始!");
            proceed = method.invoke(o);
            System.out.println("代理方法" + method.getName() + "after开始!");
        } catch (Exception e) {
            System.out.println("代理方法" + method.getName() + "afterThrowing执行!");
        }

        return proceed;
    }
}
